from machine import Pin, time_pulse_us
import time


class DISTANCE(object):
    """基本描述

    三线宽压超声波传感器

    """

    def __init__(self, pin):
        self.__pin = Pin(pin, Pin.OUT)

    def get_distance(self):
        """基本描述

        读取距离值

        Returns:
            distance: 距离
        """
        self.__pin.value(1)
        time.sleep_us(2)
        self.__pin.value(1)
        time.sleep_us(10)
        self.__pin.value(0)
        ts = time_pulse_us(self.__pin_e, 1, 25000)
        distance = ts / 58
        return distance


if __name__ == "__main__":
    dis = DISTANCE(0)
    while 1:
        print(dis.get_distance())
        time.sleep(1)
